<?php

/************************************

EasyCB, Community Forum Software
Copyright (C) 2007  Jonathon D. Keogh <jonathon.keogh@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

$Id: page.login.php 2 2007-09-01 15:06:01Z jonathon.keogh $

************************************/

require "inc.func.php";

page_header("Login to " . htmlentities(config_get("BoardName")));

print "<form action=\"" . htmlentities($_SERVER['PHP_SELF']) . "\" method=\"POST\">\n";

$_username = isset($_COOKIE['ECBLastUser']) ? $_COOKIE['ECBLastUser'] : "";

if(isset($_POST['username']))
{
	$_username = trim($_POST['username']);
	$_password = $_POST['password'];
	
	if($_username == "" || $_password == "")
	{
		$error = "All fields are required";
	} elseif(!user_check($_username, md5($_password))) {
		$error = "User name and password combination entered is not correct";
	} else {
		sess_set("UserID", user_id($_username));
		setcookie('ECBLastUser', user_name(user_id($_username)));
		page_redirect("page.boards.php");
	}
}

if(isset($error))
{
	page_section("An error occured");
	print "<b style=\"color: #FF0000;\">$error</b>";
	page_section();
}

page_section("Login");
?>

<table width="100%" cellspacing="0" cellpadding="5">
	<tr>
		<td width="200" valign="top" align="right">User name:</td>
		<td valign="top"><input name="username" size="40" value="<?=htmlentities($_username) ?>"></td>
	</tr>
	<tr>
		<td width="200" valign="top" align="right">Password:</td>
		<td valign="top"><input name="password" size="40" type="password"></td>
	</tr>
</table>

<?php
print "<p align=\"center\"><button type=\"submit\">Login</button>\n";
page_section();

print "</form>\n";

page_footer('$Id: page.login.php 2 2007-09-01 15:06:01Z jonathon.keogh $');

?>